﻿package mortal.game.view.treasureMap
{
    import Message.DB.Tables.*;
    import Message.Public.*;
    import mortal.component.window.*;
    import mortal.game.cache.*;
    import mortal.game.events.*;
    import mortal.game.manager.*;
    import mortal.game.mvc.*;
    import mortal.game.resource.*;
    import mortal.game.utils.*;
    import mortal.mvc.core.*;
    import mortal.mvc.interfaces.*;

    public class TreasureMapController extends Controller
    {
        private var _module:TreasureMapModule;

        public function TreasureMapController()
        {
            return;
        }// end function

        override protected function initView() : IView
        {
            if (this._module == null)
            {
                this._module = new TreasureMapModule();
                this._module.addEventListener(WindowEvent.SHOW, this.onShow);
                this._module.addEventListener(WindowEvent.CLOSE, this.onClose);
            }
            return this._module;
        }// end function

        override protected function initServer() : void
        {
            NetDispatcher.addCmdListener(ServerCommand.TreasureMapInfoGet, this.treasureMapOpen);
            NetDispatcher.addCmdListener(ServerCommand.Copy_EnterCopy, this.onEnterCopy);
            NetDispatcher.addCmdListener(ServerCommand.Copy_LeaveCopy, this.onLeaveCopy);
            Dispatcher.addEventListener(EventName.ActiveStart, this.iconOpen);
            Dispatcher.addEventListener(EventName.ActiveEnd, this.iconClose);
            Dispatcher.addEventListener(EventName.ActiveNotic, this.activesNoticHandler);
            Dispatcher.addEventListener(EventName.TreasureMapOpen, this.treasureMapOpen);
            Dispatcher.addEventListener(EventName.TreasureMapOper, this.treasureMapOper);
            Dispatcher.addEventListener(EventName.TreasureDigging, this.checkDigging);
            Dispatcher.addEventListener(EventName.TreasureMapShow, this.onTreasureMapShow);
            return;
        }// end function

        private function onEnterCopy(param1:Object) : void
        {
            if (cache.copy.copyInfo && cache.copy.copyInfo.type == ECopyType._ECopyTypeTreasureMap)
            {
                TreasureMapCopyRightWin.instance.show();
            }
            return;
        }// end function

        private function onLeaveCopy(param1:TCopy) : void
        {
            if (param1 && param1.type == ECopyType._ECopyTypeTreasureMap)
            {
                if (TreasureMapCopyRightWin.isViewShow)
                {
                    TreasureMapCopyRightWin.instance.hide();
                }
            }
            return;
        }// end function

        private function onShow(event:WindowEvent) : void
        {
            NetDispatcher.addCmdListener(ServerCommand.VipLevelUp, this.updateVip);
            return;
        }// end function

        private function onClose(event:WindowEvent) : void
        {
            NetDispatcher.removeCmdListener(ServerCommand.VipLevelUp, this.updateVip);
            return;
        }// end function

        private function activesNoticHandler(event:DataEvent) : void
        {
            var _loc_2:* = event.data as SClientActive;
            if (_loc_2.type == EActiveType._EActiveTypeTreasureMap)
            {
                TreasureMapIcon.instance.show();
                TreasureMapIcon.instance.setLeftTimeAndState((_loc_2.startDt.time - ClockManager.instance.nowDate.time) * 0.001, 1);
            }
            return;
        }// end function

        private function iconOpen(event:DataEvent) : void
        {
            var _loc_2:* = event.data as SClientActive;
            if (_loc_2.type == EActiveType._EActiveTypeTreasureMap)
            {
                if (Cache.instance.role.entityInfo.level >= GameDefConfig.instance.getSystemOpenLevel(53))
                {
                    TreasureMapIcon.instance.show();
                    TreasureMapIcon.instance.playEffect();
                    TreasureMapIcon.instance.setLeftTimeAndState((_loc_2.endDt.time - ClockManager.instance.nowDate.time) * 0.001, 2);
                }
            }
            return;
        }// end function

        private function iconClose(event:DataEvent) : void
        {
            var _loc_2:* = event.data as SClientActive;
            if (_loc_2.type == EActiveType._EActiveTypeTreasureMap)
            {
                TreasureMapIcon.instance.hide();
                if (TreasureMapAvctivityWin.isViewShow)
                {
                    TreasureMapAvctivityWin.instance.hide();
                }
            }
            return;
        }// end function

        private function checkDigging(event:DataEvent) : void
        {
            CopyUtil.copyCheck(this.digging);
            return;
        }// end function

        private function digging() : void
        {
            GameProxy.sceneProxy.fight(new Array(), 22001001);
            return;
        }// end function

        private function onTreasureMapShow(event:DataEvent) : void
        {
            if (TreasureMapAvctivityWin.instance.isHide)
            {
                TreasureMapAvctivityWin.instance.show();
            }
            else
            {
                TreasureMapAvctivityWin.instance.hide();
            }
            return;
        }// end function

        private function treasureMapOpen(event:DataEvent) : void
        {
            if (!this.isViewShow)
            {
                view.show();
            }
            return;
        }// end function

        private function treasureMapOper(event:DataEvent) : void
        {
            GameProxy.role.digTreasureMap(event.data as int);
            return;
        }// end function

        private function updateVip(param1:Object) : void
        {
            this._module.updateVip();
            return;
        }// end function

    }
}
